package ru.jexp.rcp.supply.swtext.factory;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;

import ru.jexp.rcp.supply.swtext.DecimalFormatter;
import ru.jexp.rcp.supply.swtext.JExpCombo;
import ru.jexp.rcp.supply.swtext.JExpDate;
import ru.jexp.rcp.supply.swtext.JExpDecimal;
import ru.jexp.rcp.supply.swtext.JExpText;

public final class JExpControlFactory {

	public static ToolItem createToolButton(Composite parent, String text) {
		ToolBar tb = new ToolBar(parent, SWT.RIGHT);
		tb.setBackground(parent.getBackground());
		ToolItem item = new ToolItem(tb, SWT.NONE);
		item.setText(text);
		item.setData("onlyText", text);
		return item;
	}

	public static ToolItem createToolButton(Composite parent,
			ImageDescriptor descriptor) {
		ToolBar tb = new ToolBar(parent, SWT.LEFT);
		tb.setBackground(parent.getBackground());
		ToolItem item = new ToolItem(tb, SWT.NONE);
		item.setImage(descriptor.createImage());
		return item;
	}

	public static Label createLabel(Composite parent, String text) {

		return createLabel(parent, text, SWT.NONE);
	}

	public static Label createLabel(Composite parent, String text, int style) {
		Label label = new Label(parent, style);
		label.setText(text);
		label.setToolTipText(text);
		label.setData("onlytext", text);
		return label;
	}

	public static Label createDecorationLabel(Composite parent, String text) {
		return JExpDecorationFactory.labelDecoration(createLabel(parent, text));
	}

	public static Button createCheck(Composite parent) {
		return new Button(parent, SWT.CHECK);
	}

	public static JExpText createText(Composite parent) {
		return new JExpText(parent, SWT.BORDER);
	}

	public static JExpText createText(Composite parent, int password) {
		return new JExpText(parent, SWT.BORDER | password);
	}

	public static JExpDecimal createDecimal(Composite parent, String editMask) {
		return new JExpDecimal(parent, SWT.BORDER | SWT.RIGHT, editMask);
	}

	public static JExpDecimal createDecimal(Composite parent) {
		return createDecimal(parent, DecimalFormatter.EDIT_MASK_6);
	}

	public static JExpDate createDate(Composite parent) {
		return new JExpDate(parent, SWT.DROP_DOWN | SWT.BORDER);
	}

	public static <TypeComboElements> JExpCombo<TypeComboElements> createCombo(
			Composite parent, int size, Class<TypeComboElements> _class) {
		return new JExpCombo<TypeComboElements>(parent, size, _class);
	}
}
